home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / Clinic / Object Browser / SetEditorFormU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-03-29  |  2.2 KB  |  92 lines

  1. unit SetEditorFormU;
  2.  
  3. {$ifdef Ver100} { Delphi 3.0x }
  4.   {$define DelphiLessThan4}
  5.   {$define DelphiLessThan5}
  6. {$endif}
  7. {$ifdef Ver110} { C++ Builder 3.0x }
  8.   {$define DelphiLessThan4}
  9.   {$define DelphiLessThan5}
  10. {$endif}
  11. {$ifdef Ver120} { Delphi 4.0x }
  12.   {$define DelphiLessThan5}
  13. {$endif}
  14.  
  15. interface
  16.  
  17. uses
  18.   TypInfo,
  19.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  20.   CheckLst, StdCtrls;
  21.  
  22. type
  23.   TSetEditorForm = class(TForm)
  24.     lstEnums: TCheckListBox;
  25.     btnOK: TButton;
  26.     btnCancel: TButton;
  27.     procedure btnOKClick(Sender: TObject);
  28.   private
  29.     FPropInfo: PPropInfo;
  30.     FObject: TObject;
  31.     SetTypeInfo, EnumTypeInfo: PTypeInfo;
  32.     SetTypeData, EnumTypeData: PTypeData;
  33.   public
  34.     constructor Create(Obj: TObject; PropInfo: PPropInfo);
  35.       {$ifndef DelphiLessThan4}reintroduce;{$endif}
  36.   end;
  37.  
  38. var
  39.   SetEditorForm: TSetEditorForm;
  40.  
  41. implementation
  42.  
  43. {$R *.DFM}
  44.  
  45. uses
  46.   PropertyHelper;
  47.  
  48. { TSetEditorForm }
  49.  
  50. constructor TSetEditorForm.Create(Obj: TObject; PropInfo: PPropInfo);
  51. var
  52.   S: ^ShortString;
  53.   Loop: Integer;
  54.   IntSet: TIntegerSet;
  55. begin
  56.   inherited Create(Application);
  57.   FObject := Obj;
  58.   FPropInfo := PropInfo;
  59.   IntSet := TIntegerSet(GetOrdProp(FObject, FPropInfo));
  60.   SetTypeInfo := FPropInfo.PropType^;
  61.   SetTypeData := GetTypeData(SetTypeInfo);
  62.   EnumTypeInfo := SetTypeData^.CompType^;
  63.   EnumTypeData := GetTypeData(EnumTypeInfo);
  64.   with EnumTypeData^ do
  65.   begin
  66.     S := @NameList;
  67.     //Loop through the enum values that can be in
  68.     //the set and add them to a check list box
  69.     for Loop := MinValue to MaxValue do
  70.     begin
  71.       lstEnums.Items.Add(S^);
  72.       if GetEnumValue(EnumTypeInfo, lstEnums.Items[lstEnums.Items.Count - 1]) in IntSet then
  73.         lstEnums.State[lstEnums.Items.Count - 1] := cbChecked;
  74.       Inc(Integer(S), Length(S^) + 1);
  75.     end
  76.   end
  77. end;
  78.  
  79. procedure TSetEditorForm.btnOKClick(Sender: TObject);
  80. var
  81.   Loop: Integer;
  82.   IntSet: TIntegerSet;
  83. begin
  84.   IntSet := [];
  85.   for Loop := 0 to lstEnums.Items.Count - 1 do
  86.     if lstEnums.State[Loop] = cbChecked then
  87.       Include(IntSet, GetEnumValue(EnumTypeInfo, lstEnums.Items[Loop]));
  88.   SetOrdProp(FObject, FPropInfo, Integer(IntSet))
  89. end;
  90.  
  91. end.
  92.